package com.tao.controller;

import com.alibaba.fastjson.JSON;
import com.tao.pojo.Coding;
import com.tao.service.CodingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.logging.ConsoleHandler;

@RestController
public class CodingController {

    @Autowired
    CodingService codingService;

    @RequestMapping("/selectCoding")
    public String select(){
        System.out.println("coding select");
        List<Coding> codings = codingService.selectAll();
        String s = JSON.toJSONString(codings);


        return s;
    }

    @RequestMapping("/delCoding/{id}")
    public String delCoding(@PathVariable int id){

        System.out.println("删除 coding");
        codingService.deleteByPrimaryKey(id);
        return JSON.toJSONString("success");
    }

    @RequestMapping("/addCoding")
    public String addCoding(Coding coding){

        System.out.println("add coding:");
        codingService.insertCoding(coding);
        System.out.println(coding);
        return JSON.toJSONString("success");
    }
}
